/**
 * @description 封装本地存储API
 * @param key 本地存储中指定的key
 * @param data 需要缓存的数据
 */
export const setStorage=(key,data)=>{
	try {
		wx.setStorageSync(key, data)
	} catch (error) {
		console.log('存储发生异常')
	 }
}
export const getStorage= (key)=>{
	try {
		const value = wx.getStorageSync(key)
		if(value){
			return value
		}
	} catch (error) {
		console.log(`读取指定${key} 数据发生异常`,error)
	}
}
export const removeStorage = (key) =>{
	try {
		wx.removeStorageSync(key)
	} catch (error) {
		console.log(`移除指定${key}数据发生异常`,error)
	}
}
/**
 * 清空、移除本地全部数据
 */
export const clearStorage = () =>{
	try {
		wx.clearStorageSync()
	} catch (error) {
		console.log(`清除数据时发生异常`,error)
		
	}
}
/**
 * @description 异步将数据存储到本地
 * @param 本地缓存中指定的key
 * @param 需要缓存的数据
 */
export const asyncSetStorage = (key,data)=>{
	return new Promise(resolve =>{
		wx.setStorage({
			key:key,
			data:data,
			//complete接口调用结束的回调函数（调用成功、失败都会执
			complete:(res)=>{
				resolve(res)
			}

		})
	})
}
export const asyncGetStorage = (key)=>{
	return new Promise(resolve =>{
		wx.getStorage({
			key,
			complete(res) {
				resolve(res)
			}
		})
	})
}
export const asyncRemoveStorage = (key)=>{
	return new Promise(resolve =>{
		wx.removeStorage({
			key,
			complete(res) {
				resolve(res)
			}
		})
	})
}
export const asyncClearStorage = ()=>{
	return new Promise(resolve =>{
		wx.clearStorage({
			complete(res){
				resolve(res)
			}
		})
	})
}